{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import math\n",
    "\n",
    "class Point(object):\n",
    "    def __init__(self, x, y):\n",
    "        super().__init__()\n",
    "        self.__x = x\n",
    "        self.__y = y\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"{super().__str__()} => Point({self.__x}, {self.__y})\"\n",
    "\n",
    "    def __eq__(self, other):\n",
    "        return self.x == other.x and self.y == other.y\n",
    "\n",
    "    @property\n",
    "    def x(self):\n",
    "        return self.__x\n",
    "\n",
    "    @x.setter\n",
    "    def x(self, value):\n",
    "        self.__x = value\n",
    "\n",
    "    @property\n",
    "    def y(self):\n",
    "        return self.__y\n",
    "\n",
    "    @y.setter\n",
    "    def y(self, value):\n",
    "        self.__y = value\n",
    "\n",
    "    def getDistance(self, other):\n",
    "        w = self.__x - other.__x\n",
    "        h = self.__y - other.__y\n",
    "        return math.sqrt(w**2 + h**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<__main__.Point object at 0x10f0ad040> => Point(2, 3)\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "p2 = Point(2, 3)\n",
    "print(p1)\n",
    "print(p1 == p2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Point(2, 3)\n",
      "5.0\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "print(p1)\n",
    "p2 = Point(5, 7)\n",
    "print(p1.getDistance(p2))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [],
   "source": [
    "class Circle:\n",
    "    def __init__(self, r, o):\n",
    "        self.r = r\n",
    "        self.o = o\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Circle(r={self.r}, o={self.o})\"\n",
    "\n",
    "    def getArea(self):\n",
    "        return math.pi * self.r**2\n",
    "\n",
    "    def getPerimeter(self):\n",
    "        return math.pi * self.r * 2"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Circle(r=5, o=Point(2, 3))\n",
      "78.53981633974483\n",
      "31.41592653589793\n",
      "5.0\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "c1 = Circle(5, p1)\n",
    "print(c1)\n",
    "print(c1.getArea())\n",
    "print(c1.getPerimeter())\n",
    "\n",
    "p2 = Point(5, 7)\n",
    "print(c1.o.getDistance(p2))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Circle(r=5, o=Point(2, 3))\n",
      "Circle(r=7, o=Hello, World!)\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "c1 = Circle(5, p1)\n",
    "p2 = \"Hello, World!\"\n",
    "c2 = Circle(7, p2)\n",
    "print(c1)\n",
    "print(c2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [],
   "source": [
    "class Point3D:\n",
    "    def __init__(self, x, y, z):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "        self.z = z\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Point3D({self.x}, {self.y}, {self.z})\"\n",
    "\n",
    "    def getDistance(self, other):\n",
    "        w = self.x - other.x\n",
    "        h = self.y - other.y\n",
    "        s = self.z - other.z\n",
    "        return math.sqrt(w**2 + h**2 + s**2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Circle(r=5, o=Point(2, 3))\n",
      "Circle(r=7, o=Point3D(5, 7, 9))\n"
     ]
    }
   ],
   "source": [
    "p1 = Point(2, 3)\n",
    "c1 = Circle(5, p1)\n",
    "print(c1)\n",
    "print(\"===\")\n",
    "p2 = Point3D(5, 7, 9)\n",
    "c2 = Circle(7, p2)\n",
    "print(c2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [],
   "source": [
    "class Sphere(Point3D):\n",
    "    def __init__(self, r, x, y, z):\n",
    "        super().__init__(x, y, z)\n",
    "        self.r = r\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"Sphere(r={self.r}, o={super().__str__()})\"\n",
    "\n",
    "    def getArea(self):\n",
    "        return 4 * math.pi * self.r**2\n",
    "\n",
    "    def getVolume(self):\n",
    "        return 4 / 3 * math.pi * self.r**3"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sphere(r=5, o=Point3D(2, 3, 5))\n",
      "314.1592653589793\n",
      "523.5987755982989\n",
      "===\n",
      "Sphere(r=7, o=Point3D(7, 11, 13))\n",
      "615.7521601035994\n",
      "1436.7550402417319\n",
      "===\n",
      "12.36931687685298\n"
     ]
    }
   ],
   "source": [
    "s1 = Sphere(5, 2, 3, 5)\n",
    "s2 = Sphere(7, 7, 11, 13)\n",
    "print(s1)\n",
    "print(s1.getArea())\n",
    "print(s1.getVolume())\n",
    "print(\"===\")\n",
    "print(s2)\n",
    "print(s2.getArea())\n",
    "print(s2.getVolume())\n",
    "print(\"===\")\n",
    "print(s1.getDistance(s2))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Bat\n",
      "Hello, I'm bat\n",
      "Hello, I'm man\n",
      "===\n",
      "Man\n",
      "Hello, I'm bat\n",
      "Hello, I'm man\n"
     ]
    }
   ],
   "source": [
    "class Bat:\n",
    "    def __init__(self):\n",
    "        self.name = \"Bat\"\n",
    "\n",
    "    def __str__(self):\n",
    "        return self.name\n",
    "\n",
    "    def helloFromBat(self):\n",
    "        return \"Hello, I'm bat\"\n",
    "\n",
    "class Man:\n",
    "    def __init__(self):\n",
    "        self.name = \"Man\"\n",
    "\n",
    "    def __str__(self):\n",
    "        return self.name\n",
    "\n",
    "    def helloFromMan(self):\n",
    "        return \"Hello, I'm man\"\n",
    "\n",
    "class BatMan1(Bat, Man):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "\n",
    "    def __str__(self):\n",
    "        return self.name\n",
    "\n",
    "class BatMan2(Man, Bat):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "\n",
    "    def __str__(self):\n",
    "        return self.name\n",
    "\n",
    "bm1 = BatMan1()\n",
    "print(bm1)\n",
    "print(bm1.helloFromBat())\n",
    "print(bm1.helloFromMan())\n",
    "print(\"===\")\n",
    "bm2 = BatMan2()\n",
    "print(bm2)\n",
    "print(bm2.helloFromBat())\n",
    "print(bm2.helloFromMan())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}